package com.baofu.paycore.service.validate.impl.withdraw;

import com.baofu.paycore.common.enums.RedisKeyEnum;
import com.baofu.paycore.common.exception.ManagerErrorCode;
import com.baofu.paycore.common.exception.PayCoreBizException;
import com.baofu.paycore.common.exception.ValidateException;
import com.baofu.paycore.common.utils.Constant;
import com.baofu.paycore.common.utils.RedisKeyUtil;
import com.baofu.paycore.manager.cache.RedisManager;
import com.baofu.paycore.manager.model.FreezeBO;
import com.baofu.paycore.manager.storer.FreezeOrderRepository;
import com.baofu.paycore.manager.storer.PreAuthRepository;
import com.baofu.paycore.service.facade.enums.PayCoreErrorCode;
import com.baofu.paycore.service.facade.enums.PayStatusEnums;
import com.baofu.paycore.service.facade.model.withdraw.UnfreezeWithdrawDTO;
import com.baofu.paycore.service.validate.AbstractPayValidate;
import com.system.commons.exception.BizServiceException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 提现类校验
 *
 * User: LZQ Date: 2016/05/19  Version: 1.0
 */
@Slf4j
@Service
public class UnfreezeWithdrawValidate extends AbstractPayValidate<UnfreezeWithdrawDTO> {

    /**
     * 冻结服务
     */
    @Autowired
    private FreezeOrderRepository freezeOrderRespository;

    /**
     * redis服务
     */
    @Autowired
    private RedisManager redisManager;

    /**
     * 解冻提现参数校验
     *
     * @param t     被校验对象
     */
    public void paramsValidate(UnfreezeWithdrawDTO t){
        super.paramsValidate(t);

        if (!t.getAmt().equals(t.getWithDrawFundDTO().getAmt())){
            log.error("解冻提现主单总金额:{} 资金单充值金额:{} 资金单业务手续费金额:{}", t.getWithDrawFundDTO().getAmt(),
                    t.getWithDrawFundDTO().getAmt(), Constant.validateLong(
                            t.getWithDrawFundDTO().getBizChargeAmount()));
            throw new ValidateException(PayCoreErrorCode.AMT_IS_NOT_IN_CONFORMITY);
        }

        if (t.getAmt() <= Constant.validateLong(t.getWithDrawFundDTO().getBizChargeAmount())){
            log.error("解冻提现主单总金额:{} 资金单充值金额:{} 资金单业务手续费金额:{}", t.getWithDrawFundDTO().getAmt(),
                    t.getWithDrawFundDTO().getAmt(), Constant.validateLong(
                            t.getWithDrawFundDTO().getBizChargeAmount()));
            throw new BizServiceException(PayCoreErrorCode.FEE_AMT_NOT_MORE_PAY_AMT);
        }
    }
}
